﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel.Syndication;
using System.Text;
using System.Threading.Tasks;
using System.Xml;

namespace RSSDataPump
{
    class RSSRead
    {
        
        public void RssFeed(String url)
        {
            XmlReader reader = XmlReader.Create(url);
            SyndicationFeed feed = SyndicationFeed.Load(reader);
            List<RSSData> rdList = new List<RSSData>();
            
            foreach (SyndicationItem item in feed.Items)
            {
                RSSData rd = new RSSData();
                rd.title = item.Title.Text;
                rd.summary = item.Summary.Text;
                rd.date = item.PublishDate.UtcDateTime.ToString();
                rd.source = url;
                rdList.Add(rd);
            }
            //insert into DB
            foreach (RSSData rd2 in rdList)
            {
                RSSDataPump.SqlDB.insertNews(rd2);
            }
        }
    }
}
